package com.app.dao;

import com.app.pojo.User;
import com.app.pojo.UserPassword;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

public interface UserDao {

    /*----------------select--------------------*/
    @Select("SELECT user.userId,password FROM user LEFT JOIN user_private ON user.userId=user_private.userId WHERE email = #{email}")
    UserPassword findUserPasswdByEmail(String email);

    @Select("SELECT password FROM user_pw WHERE userId = #{userId}")
    String findPasswdById(String userId);

    @Select("SELECT * FROM user WHERE nickname = #{nickname}")
    User finUserByName(String nickname);
    
    @Select("SELECT * FROM user WHERE email = #{email}")
    User finUserByEmail(String email);

    @Select("SELECT * FROM user WHERE userId = #{userId}")
    User finUserById(String userId);

    /*----------------insert--------------------*/
    int addUser(User user);


    /*----------------delete--------------------*/

    int deleteUser(String userId);

    /*----------------labels--------------------*/

    @Select("SELECT label FROM user_labels WHERE userId = #{userId}")
    String[] findLabelsByUserId(String userId);

    @Insert("INSERT INTO user_labels(userId,label) VALUES (#{userId},#{label})")
    int addLabel(String userId,String label);

    @Delete("DELETE FROM user_labels WHERE userId = #{userId} AND label = #{label}")
    int deleteLabel(String userId,String label);

    @Delete("DELETE FROM user_labels WHERE userId = #{userId}")
    int deleteLabelsById(String userId);

}
